package com.kjsdfgk.hjmdsf.ftmzt.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.google.android.material.tabs.TabLayout;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.kjsdfgk.hjmdsf.ftmzt.di.component.DaggerMeiZhiTuComponent;
import com.kjsdfgk.hjmdsf.ftmzt.mvp.contract.MeiZhiTuContract;
import com.kjsdfgk.hjmdsf.ftmzt.mvp.presenter.MeiZhiTuPresenter;
import com.kjsdfgk.hjmdsf.ftmztlist.mvp.ui.fragment.MZTListFragment;
import com.kjsdfgk.hjmdsf.livev3.mvp.ui.activity.PagerFragmentStatePager;
import com.lksdkjs.live.R;


import java.util.ArrayList;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 05/07/2020 13:28
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class MeiZhiTuFragment extends BaseFragment<MeiZhiTuPresenter> implements MeiZhiTuContract.View {

    public static MeiZhiTuFragment newInstance() {
        MeiZhiTuFragment fragment = new MeiZhiTuFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerMeiZhiTuComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_mei_zhi_tu, container, false);
    }
    @BindView(R.id.layout_tabLayout)
    TabLayout mTabLayout;

    @BindView(R.id.layout_pager)
    ViewPager mViewPager;
    public final String[] CATEGORY_VALUE = {"女神","长腿", "气质", "尤物","极品", "嫩模","网红", "诱惑", "性感", "美胸", "爆乳"};
    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
     //   Glide.with(getActivity()).load(buildGlideUrl("https://i.mmzztt.com/thumb/2020/05/209307_236.jpg")).transition(new DrawableTransitionOptions().crossFade(300)).into(image);
        final ArrayList<Fragment> listFragments = new ArrayList<>();
        for (String str:CATEGORY_VALUE) {
            mTabLayout.addTab(mTabLayout.newTab().setText(str));
            Bundle bundle = new Bundle();
            bundle.putString( "category" , str );
            MZTListFragment fragment =  new MZTListFragment();
            fragment.setArguments(bundle);
            listFragments.add(fragment);
        }
        PagerFragmentStatePager pagerAdapter = new PagerFragmentStatePager(getChildFragmentManager());
        mViewPager.setAdapter(pagerAdapter);
        mViewPager.setOffscreenPageLimit(5);
        mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
        mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

        pagerAdapter.setListFragments(listFragments);
        pagerAdapter.notifyDataSetChanged();
    }



    @Override
    public void setData(@Nullable Object data) {

    }


    @Override
    public void showLoading(String key) {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public boolean isCancel() {
        return false;
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    private GlideUrl buildGlideUrl(String url) {
        if (TextUtils.isEmpty(url)) {
            return null;
        } else {
            return new GlideUrl(url, new LazyHeaders.Builder()
                    //.addHeader("Accept-Language", "zh-CN,zh;q=0.9,zh-TW;q=0.8")
                    //.addHeader("Host", "i.meizitu.net")
                    .addHeader("Referer", "https://www.mzitu.com/")
                    .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36")
                    .build());
        }
    }
}
